package cn.gson.springboot.controller.privilegecontroller;

import cn.gson.springboot.model.pjos.Dept;
import cn.gson.springboot.model.pjos.Emp;
import cn.gson.springboot.model.pjos.Position;
import cn.gson.springboot.model.service.privilegeservice.EmpService;
import cn.gson.springboot.model.vo.privilegevo.DepartmentVo;
import cn.gson.springboot.model.vo.privilegevo.DeptVo;
import cn.gson.springboot.model.vo.privilegevo.FirstPost;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/emp")
public class EmpController {

    @Autowired
    EmpService empService;//注入员工业务类

    /**
     * 查询部门
     * @return
     */
    @RequestMapping("/depts")
    @ResponseBody
    public List<Dept> depts(){
        return  empService.depts();
    }

    /**
     * 根据部门查询出对应的角色
     * @param deptId
     * @return
     */

    @RequestMapping("/positions")
    @ResponseBody
    public List<Position> positions(int deptId){
        return empService.positions(deptId);
    }

    /**
     * 新增或修改员工
     * @param emp
     */
    @RequestMapping("/save_emp")
    @ResponseBody
    public void saveEmp(@RequestBody Emp emp){
        System.err.println("员工:"+emp.toString());
        empService.saveEmp(emp);
    }

    /**
     * 查询员工
     * @param empName
     * @return
     */
    @RequestMapping("/select_emp")
    @ResponseBody
    public List<DepartmentVo> selectEmp(String empName){
        return empService.selectEmp(empName);
    }

    /**
     * 查询员工名称是否存在
     * @param empName
     * @return
     */
    @RequestMapping("/is_no_emp")
    @ResponseBody
    public int  isNoEmp(String empName){
       return empService.isNoEmp(empName);
    }

    /**
     * 修改员工的状态
     * @param employeesId
     * @param empIsNot
     */
    @RequestMapping("/update_emp_status")
    @ResponseBody
    public void updateEmpStatus(Integer employeesId,String empIsNot){
        empService.updateEmpStatus(employeesId,empIsNot);
    }

    /**
     * 删除员工
     * @param empId
     */
    @RequestMapping("/delete_emp")
    @ResponseBody
    public void deleteEmp(Integer empId){
        empService.deleteEmp(empId);
    }

    /**
     * 验证联系电话是否重复
     * @param phone
     * @return
     */
    @RequestMapping("/emp_phone")
    @ResponseBody
    public  int phone(String phone){
        return empService.phone(phone);
    }

    /**
     *验证身份证号是否重复
     * @param card
     * @return
     */
    @RequestMapping("/emp_card")
    @ResponseBody
    public  int card(String card){
        return empService.card(card);
    }

    /**
     * 查询部门下的一级职位是否已有员工
     * @param deptId
     * @return
     */
    @RequestMapping("/is_first_post")
    @ResponseBody
    public FirstPost isFirstPost(Integer deptId){
        return empService.isFirstPost(deptId);
    }
}
